package com.example.exchangeapp.zjs;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    //数据库表的创建和删除 SQL 语句
    private static final String SQL_CREATE_ENTRIES = "CREATE TABLE " + "Users" + " (" +
            "ID" + " INTEGER PRIMARY KEY," +
            "phoneNumber" + " VARCHAR(50) NOT NULL, " +
            "money" + " DOUBLE, " +
            "avatar" + " VARCHAR(200) " + ")" ;

    //删除数据库
    private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + "Users";

    //如果更改数据库架构，则必须增加数据库版本
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "Users.db";

    public MySQLiteOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    //重写创建表的逻辑
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES);
    }

    //重写数据库升级逻辑
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase , int oldVersion , int newVersion) {
        sqLiteDatabase.execSQL(SQL_DELETE_ENTRIES);
        onCreate(sqLiteDatabase);
    }


}
